package com.sky.controller.user;

import com.sky.constant.MessageConstant;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Api(tags = "下单")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    @ApiOperation("下单")
    public Result<OrderSubmitVO> orderSubmit(@RequestBody OrdersSubmitDTO submitDTO){

        OrderSubmitVO vo = orderService.orderSubmit(submitDTO);
        return Result.success(vo);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }


    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> OrderDetail(@PathVariable Long id){
        return Result.success(orderService.orderDetail(id));
    }


    @GetMapping("/historyOrders")
    public Result<PageResult> HistoryOrders(Integer page,Integer pageSize,Integer status){
        return Result.success(orderService.HistoryOrders(page,pageSize,status));
    }


    @PutMapping("/cancel/{id}")
    public Result CancelOrder(@PathVariable Long id) throws Exception {
        orderService.CancelOrder(id);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    public Result RepetitionOrder(@PathVariable Long id) throws Exception {
        orderService.RepetitionOrder(id);
        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    public Result ReminderOrder(@PathVariable Long id) throws Exception {
        orderService.ReminderOrder(id);
        return Result.success();
    }
}
